﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;

namespace ExFlash.Actions
{
    [TypeConverter(typeof(ExpandableObjectConverter))]
    public class ActionPush : ActionRecord
    {
        private readonly int _swfVersion;
        
        public List<ActionPushTypeValuePair> Items
        {
            get;
            private set;
        }
        
        public ActionPush(ushort len, int version)
            : base((byte)ActionCodes.ActionPush, len)
        {
            _swfVersion = version;
        }
        
        public override void SwfDeserialize(BinaryBitReader reader)
        {
            long startIndex = reader.Position;

            Items = new List<ActionPushTypeValuePair>();

            while (reader.Position - startIndex < Length)
            {
                ActionPushTypeValuePair pair = new ActionPushTypeValuePair(_swfVersion);
                pair.SwfDeserialize(reader);
                Items.Add(pair);
            }

            if (reader.Position - startIndex != Length)
            {
                throw new SerializationException("Data mismatches Action Record length");
            }
        }

        public override void SwfSerialize(byte[] arr, ref int offset)
        {
            throw new NotImplementedException();
        }
    }
}
